package com.yoda.controller.user;


import com.yoda.entity.YddUser;
import com.yoda.result.Result;
import com.yoda.service.IYddUserService;
import com.yoda.vo.AddArticleVo;
import io.swagger.util.Yaml;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IYddUserService userService;

    /**
     * 个人界面
     * @return
     */
    @GetMapping("/getUserInfo")
    public Result getUserInfo(){

        return userService.getUserInfo();
    }

    @GetMapping("/myArticle")
    public Result myArticle(@RequestParam(value = "page")String page, @RequestParam(value = "limit") String pageSize){
        return userService.myArticle(page,pageSize);
    }

    /**
     *  我的收藏/点赞文章
     * @param type
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userDataList")
    public Result userDataList(@RequestParam(value = "type")String type,
            @RequestParam(value = "page")String page,
            @RequestParam(value = "limit") String pageSize){
        return userService.userDataList(type,page,pageSize);
    }

    @PostMapping("/addArticle")
    public Result addArticle(@RequestBody AddArticleVo vo){
        return userService.addArticle(vo);
    }

    @GetMapping("/userDataHandle")
    public Result userDataHandle(
            @RequestParam(value = "type")String type,
            @RequestParam(value = "article_id")String articleId,
            @RequestParam(value = "action") String action
    ){
        return userService.userDataHandle(type,articleId,action);
    }

    @PostMapping("/update")
    public Result updateUser(@RequestBody YddUser yddUser){
        return userService.updateUser(yddUser);
    }
}
